use std::mem::size_of_val;

use crate::gen_title;

/// ### 字符类型
pub fn ch2_3_1() {
    gen_title("ch2_3_1", 18);

    let c = 'z';
    let z = 'Z';
    let g = '国';
    let heart_eyed_cat = '🤡';

    println!(
        "c = {}, z = {}, g = {}, heart = {}",
        c, z, g, heart_eyed_cat
    );
}

pub fn ch2_3_2() {
    gen_title("ch2_3_2", 18);

    let x = '中';
    println!("字符'中'占用了{}字节的内存大小", std::mem::size_of_val(&x));
}

pub fn ch2_3_3() {
    gen_title("ch2_3_3", 18);

    let t = true;

    let f: bool = false;

    if f {
        println!("这是段毫无意义的代码");
    }
    println!("t = {}", t);
}

pub fn ch2_3_pra_1() {
    gen_title("ch2_3_pra_1", 18);

    let c1 = 'a';
    assert_eq!(size_of_val(&c1), 4);

    let c2 = '中';
    assert_eq!(size_of_val(&c2), 4);

    println!("Success!");
}

pub fn ch2_3_pra_2() {
    gen_title("ch2_3_pra_2", 18);

    let c1 = '中';
    print_char(c1);
}

fn print_char(c: char) {
    println!("{}", c);
}

pub fn ch2_3_pra_3() {
    gen_title("ch2_3_pra_3", 18);

    let _f: bool = false;

    let t = false;

    if !t {
        println!("Success");
    }
}

pub fn ch2_3_pra_4() {
    gen_title("ch2_3_pra_4", 18);

    let f = true;
    let t = true || false;
    assert_eq!(t, f);

    println!("Success!");
}

pub fn ch2_3_pra_5() {
    gen_title("ch2_3_pra_5", 18);

    let _v: () = ();

    let v = (2, 3);
    assert_eq!(_v, implicitly_ret_unit());

    println!("Success!");
}

fn implicitly_ret_unit() {
    println!("I will return a ()");
}

fn explicitly_ret_unit() -> () {
    println!("I will return a ()");
}

pub fn ch2_3_pra_6() {
    gen_title("ch2_3_pra_6", 18);

    let unit: () = ();
    assert_eq!(size_of_val(&unit), 0);

    println!("Success!");
}
